Skip to content

_run_cmd: override user aliases in run()#1359

Merged
RonnyPfannschmidt merged 1 commit into
pypa:mainfrom
muxator:HGRCPATH
Apr 25, 2026
Merged

_run_cmd: override user aliases in run()#1359
RonnyPfannschmidt merged 1 commit into
pypa:mainfrom
muxator:HGRCPATH

Conversation

@muxator
Copy link
Copy Markdown
Contributor

@muxator muxator commented Apr 7, 2026

If a user aliased hg log to hg log --graph 1 (apparently this is widespread, see 2), mercurial based setups do not work, because hg log output needs to be reset to a canonical form.

This is done setting the environment variable HGRCPATH= to an empty value.

A previous attempt at normalizing hg output was done on 2010-08-29, when e0954e3 ("inline getoutput, set HGPLAIN to disable hg i18n"), introduced HGPLAIN=1, but this change is not sufficient for protecting against hg log aliasing.

An example of command that is fixed with this change is the compilation of mercurial itself in local mode (here shown for 7.2.1):

  $ make local
  ...
  File "<HOME>/.cache/uv/builds-v0/.tmpcFxMQB/lib64/python3.14/site-packages/vcs_versioning/_run_cmd.py", line 173, in run
    res.check_returncode()
    ~~~~~~~~~~~~~~~~~~~~^^
  File "/usr/lib64/python3.14/subprocess.py", line 508, in check_returncode
    raise CalledProcessError(self.returncode, self.args, self.stdout,
                             self.stderr)
subprocess.CalledProcessError: Command '['hg', 'log', '-r', '.', '-T', '{node}\n{tag}\n{date|shortdate}']' returned non-zero exit status 255.

Footnotes

  1. hg log can be aliased editing the contents of hgrc:

    [alias]
    log = log --graph
    
  2. https://foss.heptapod.net/mercurial/mercurial-devel/-/commit/604c086ddde6f40309c03ae7e5050c7c8d87e75a

If a user aliased "hg log" to "hg log --graph" [^1] (apparently this is
widespread, see [^2]), mercurial based setups do not work, because "hg log"
output needs to be reset to a canonical form.

This is done setting the environment variable HGRCPATH= to an empty value.

A previous attempt at normalizing hg output was done on 2010-08-29, when
e0954e3 ("inline getoutput, set HGPLAIN to disable hg i18n"), introduced
HGPLAIN=1, but this change is not sufficient for protecting against `hg log`
aliasing.

An example of command that is fixed with this change is the compilation of
mercurial itself in local mode (here shown for 7.2.1):

```
  $ make local
  ...
  File "<HOME>/.cache/uv/builds-v0/.tmpcFxMQB/lib64/python3.14/site-packages/vcs_versioning/_run_cmd.py", line 173, in run
    res.check_returncode()
    ~~~~~~~~~~~~~~~~~~~~^^
  File "/usr/lib64/python3.14/subprocess.py", line 508, in check_returncode
    raise CalledProcessError(self.returncode, self.args, self.stdout,
                             self.stderr)
subprocess.CalledProcessError: Command '['hg', 'log', '-r', '.', '-T', '{node}\n{tag}\n{date|shortdate}']' returned non-zero exit status 255.
```

[^1]: `hg log` can be aliased editing the contents of `hgrc`:
    ```
    [alias]
    log = log --graph
    ```

[^2]: https://foss.heptapod.net/mercurial/mercurial-devel/-/commit/604c086ddde6f40309c03ae7e5050c7c8d87e75a
@muxator
Copy link
Copy Markdown
Contributor Author

muxator commented Apr 24, 2026

Hi, can this PR be considered for review?

@RonnyPfannschmidt
Copy link
Copy Markdown
Contributor

rtd error unrelated, thanks

@RonnyPfannschmidt RonnyPfannschmidt merged commit e2e15d0 into pypa:main Apr 25, 2026
26 of 27 checks passed
@muxator
Copy link
Copy Markdown
Contributor Author

muxator commented Apr 26, 2026

Thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants